﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_WFEVENTS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public DataRow SaveICC_WFEVENTS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;

            Result = QueryICC_WFEVENTS(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_WFEVENTS(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] = GetSeq();
                InsertICC_WFEVENTS(dwLocal, ITXDBVERSION);
            }
            UpdateICC_WFEVENTS(dwLocal);
            return dwLocal;
        }
        public void InsertICC_WFEVENTS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                    or1.CommandText = "INSERT INTO ICC_WFEVENTS(MANDANT,ROWNID,USERGROUP,WFEUSER,WFEVENTS,WFEHANDLER,WFSOURCE,WHAT,HOW,ORDTYPE,KRS,LFD,POS,ARTTYPE,ARTICLE,COLOR,P1)"
                                + " VALUES (:MANDANT,:ROWNID,:USERGROUP,:WFEUSER,:WFEVENTS,:WFEHANDLER,:WFSOURCE,:WHAT,:HOW,:ORDTYPE,:KRS,:LFD,:POS,:ARTTYPE,:ARTICLE,:COLOR,:P1)";
                    break;
                default:
                    break;
            }
            //+ "WFEHANDLER=:WFEHANDLER,"
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("USERGROUP", OracleType.NVarChar).Value = dwData["USERGROUP"].ToString();
            or1.Parameters.Add("WFEUSER", OracleType.NVarChar).Value = dwData["WFEUSER"].ToString();
            or1.Parameters.Add("WFEVENTS", OracleType.NVarChar).Value = dwData["WFEVENTS"].ToString();
            or1.Parameters.Add("WFEHANDLER", OracleType.NVarChar).Value = dwData["WFEHANDLER"].ToString();
            or1.Parameters.Add("WFSOURCE", OracleType.NVarChar).Value = dwData["WFSOURCE"].ToString();
            or1.Parameters.Add("WHAT", OracleType.NVarChar).Value = dwData["WHAT"].ToString();
            or1.Parameters.Add("HOW", OracleType.NVarChar).Value = dwData["HOW"].ToString();
            or1.Parameters.Add("ORDTYPE", OracleType.NVarChar).Value = dwData["ORDTYPE"].ToString();
            or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
            or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
            or1.Parameters.Add("POS", OracleType.NVarChar).Value = dwData["POS"].ToString();
            or1.Parameters.Add("ARTTYPE", OracleType.NVarChar).Value = dwData["ARTTYPE"].ToString();
            or1.Parameters.Add("ARTICLE", OracleType.NVarChar).Value = dwData["ARTICLE"].ToString();
            or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString();
            or1.Parameters.Add("P1", OracleType.NVarChar).Value = dwData["P1"].ToString();
            Connect2Proxy(or1);
        }

        public DataSet QueryICC_WFEVENTS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE"
                    + " MANDANT=:MANDANT AND (WFEUSER LIKE '" + dwData["WFEUSER"].ToString().Trim() + "%'"
                    + " OR WFSOURCE LIKE  '" + dwData["WFSOURCE"].ToString().Trim() + "%'"
                    + " ) AND WFEVENTS LIKE  '" + dwData["WFEVENTS"].ToString().Trim() + "%'"
                    + " AND CONTROL LIKE  '" + dwData["CONTROL"].ToString().Trim() + "%'"
                    +" AND KRS LIKE  '" + dwData["KRS"].ToString().Trim() + "%'"
                    +" AND LFD LIKE  '" + dwData["LFD"].ToString().Trim() + "%'";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT AND WFEVENTS=:WFEVENTS AND ARTICLE=:ARTICLE AND COLOR=:COLOR "; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("WFEVENTS", OracleType.NVarChar).Value = dwData["WFEVENTS"].ToString();
                    or1.Parameters.Add("ARTICLE", OracleType.NVarChar).Value = dwData["ARTICLE"].ToString();
                    or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString();
                    break;
                case 4:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT AND KRS=:KRS AND LFD=:LFD"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    break;
                case 5:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT AND WFEVENTS=:WFEVENTS AND CONTROL=:CONTROL AND WFEUSER=:WFEUSER"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("WFEVENTS", OracleType.NVarChar).Value = dwData["WFEVENTS"].ToString();
                    or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
                    or1.Parameters.Add("WFEUSER", OracleType.NVarChar).Value = dwData["WFEUSER"].ToString();
                    break;                                  
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  MANDANT=:MANDANT AND WFEVENTS=:WFEVENTS AND ORDTYPE=:ORDTYPE AND KRS=:KRS AND LFD=:LFD AND ARTTYPE=:ARTTYPE AND ARTICLE=:ARTICLE AND COLOR=:COLOR "; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("WFEVENTS", OracleType.NVarChar).Value = dwData["WFEVENTS"].ToString();
                    or1.Parameters.Add("ORDTYPE", OracleType.NVarChar).Value = dwData["ORDTYPE"].ToString();
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    or1.Parameters.Add("ARTTYPE", OracleType.NVarChar).Value = dwData["ARTTYPE"].ToString();
                    or1.Parameters.Add("ARTICLE", OracleType.NVarChar).Value = dwData["ARTICLE"].ToString();
                    or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString();
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_WFEVENTS";
            Return = Result;
            return Return;
        }
        public DataSet QueryICC_WFEVENTS(string wfid,int option=1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_WFEVENTS WHERE  ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = wfid;
                    break; 
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_WFEVENTS";
            Return = Result;
            return Return;
        }
        public void DeleteICC_WFEVENTS(DataRow dwData, int option = 1)
        {
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_WFEVENTS WHERE  ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ICC_WFEVENTS WHERE  WHAT=:WHAT"; ;
                    or1.Parameters.Add("WHAT", OracleType.NVarChar).Value = dwData["WHAT"].ToString();
                    break;
            }
            Connect2Proxy(or1);
        }
        public void UpdateICC_WFEVENTS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            #region====Command==
            or1.CommandText = "UPDATE ICC_WFEVENTS SET "
                    +"MANDANT=:MANDANT,"
                    +"CONTROL=:CONTROL,"
                    +"USERGROUP=:USERGROUP,"
                    +"WFEUSER=:WFEUSER,"
                    +"WFEVENTS=:WFEVENTS,"
                    +"WFEHANDLER=:WFEHANDLER,"
                    +"WFSOURCE=:WFSOURCE,"
                    + "WFWHEN=:WFWHEN,"
                    +"WHAT=:WHAT,"
                    +"HOW=:HOW,"
                    +"ORDTYPE=:ORDTYPE,"
                    +"KRS=:KRS,"
                    +"LFD=:LFD,"
                    +"POS=:POS,"
                    +"ARTTYPE=:ARTTYPE,"
                    +"ARTICLE=:ARTICLE,"
                    +"ARTDES=:ARTDES,"
                    +"VAR=:VAR,"
                    +"COLOR=:COLOR,"
                    +"CDES=:CDES,"
                    +"ASIZE=:ASIZE,"
                    +"FINISH=:FINISH,"
                    +"FINDES=:FINDES,"
                    +"P1=:P1,"
                    +"P2=:P2,"
                    +"P3=:P3,"
                    +"P4=:P4,"
                    +"P5=:P5,"
                    +"P6=:P6,"
                    +"NEWUSER=:NEWUSER,"
                    +"NEWTIME=:NEWTIME,"
                    +"CHGUSER=:CHGUSER,"
                    +"CHGTIME=:CHGTIME "
                + " WHERE  "
                + "    ROWNID=:ROWNID ";
            #endregion
            #region====Parameters====
         or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
         or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
         or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
         or1.Parameters.Add("USERGROUP", OracleType.NVarChar).Value = dwData["USERGROUP"].ToString();
         or1.Parameters.Add("WFEUSER", OracleType.NVarChar).Value = dwData["WFEUSER"].ToString();
         or1.Parameters.Add("WFEVENTS", OracleType.NVarChar).Value = dwData["WFEVENTS"].ToString();
         or1.Parameters.Add("WFEHANDLER", OracleType.NVarChar).Value = dwData["WFEHANDLER"].ToString();
         or1.Parameters.Add("WFSOURCE", OracleType.NVarChar).Value = dwData["WFSOURCE"].ToString();
         or1.Parameters.Add("WFWHEN", OracleType.NVarChar).Value = dwData["WFWHEN"].ToString();
         or1.Parameters.Add("WHAT", OracleType.NVarChar).Value = dwData["WHAT"].ToString();
         or1.Parameters.Add("HOW", OracleType.NVarChar).Value = dwData["HOW"].ToString();
         or1.Parameters.Add("ORDTYPE", OracleType.NVarChar).Value = dwData["ORDTYPE"].ToString();
         or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
         or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
         or1.Parameters.Add("POS", OracleType.NVarChar).Value = dwData["POS"].ToString();
         or1.Parameters.Add("ARTTYPE", OracleType.NVarChar).Value = dwData["ARTTYPE"].ToString();
         or1.Parameters.Add("ARTICLE", OracleType.NVarChar).Value = dwData["ARTICLE"].ToString();
         or1.Parameters.Add("ARTDES", OracleType.NVarChar).Value = dwData["ARTDES"].ToString();
         or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"].ToString();
         or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString();
         or1.Parameters.Add("CDES", OracleType.NVarChar).Value = dwData["CDES"].ToString();
         or1.Parameters.Add("ASIZE", OracleType.NVarChar).Value = dwData["ASIZE"].ToString();
         or1.Parameters.Add("FINISH", OracleType.NVarChar).Value = dwData["FINISH"].ToString();
         or1.Parameters.Add("FINDES", OracleType.NVarChar).Value = dwData["FINDES"].ToString();
         or1.Parameters.Add("P1", OracleType.NVarChar).Value = dwData["P1"].ToString();
         or1.Parameters.Add("P2", OracleType.NVarChar).Value = dwData["P2"].ToString();
         or1.Parameters.Add("P3", OracleType.NVarChar).Value = dwData["P3"].ToString();
         or1.Parameters.Add("P4", OracleType.NVarChar).Value = dwData["P4"].ToString();
         or1.Parameters.Add("P5", OracleType.NVarChar).Value = dwData["P5"].ToString();
         or1.Parameters.Add("P6", OracleType.NVarChar).Value = dwData["P6"].ToString();
         or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString();
         or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString();
         or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString();
         or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString();
                    #endregion
            Connect2Proxy(or1);
        }
    }
}
